import 'package:PLDroidMediaStreaming/model/CameraStreamingSetting/CameraStreamingSetting.dart';
import 'package:PLDroidMediaStreaming/model/MicrophoneStreamingSetting.dart';
import 'package:PLDroidMediaStreaming/model/StreamingProfile/StreamingProfile.dart';
import 'package:PLDroidMediaStreaming/model/WatermarkSetting.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

class MediaStreamingManager {

  static const MethodChannel _channel = const MethodChannel('PLDroidMediaStreaming');

  int viewId;

  StreamingProfile streamingProfile;
  CameraStreamingSetting cameraStreamingSetting;
  MicrophoneStreamingSetting microphoneStreamingSetting;
  WatermarkSetting watermarkSetting;

  MediaStreamingManager({
    @required this.streamingProfile,
    @required this.cameraStreamingSetting,
    this.microphoneStreamingSetting,
    this.watermarkSetting
  });

  Map<String, dynamic> toJson() {
    return {
      "streamingProfile": streamingProfile?.toJson(),
      "cameraStreamingSetting": cameraStreamingSetting?.toJson(),
      "microphoneStreamingSetting": microphoneStreamingSetting?.toJson(),
      "watermarkSetting": watermarkSetting?.toJson(),
    };
  }

  bindViewId(int id) {
    viewId = id;
  }

  Future setStreamingProfile(StreamingProfile profile) async {
    await _channel.invokeMethod("setStreamingProfile", {
      "viewId": viewId,
      "profile": profile?.toJson()
    });
  }

  Future setCameraStreamingSetting(CameraStreamingSetting setting) async {
    await _channel.invokeMethod("setCameraStreamingSetting", {
      "viewId": viewId,
      "setting": setting?.toJson()
    });
  }

  Future setMicrophoneStreamingSetting(MicrophoneStreamingSetting setting) async {
    await _channel.invokeMethod("setMicrophoneStreamingSetting", {
      "viewId": viewId,
      "setting": setting?.toJson()
    });
  }

  Future setWatermarkSetting(WatermarkSetting setting) async {
    await _channel.invokeMethod("setWatermarkSetting", {
      "viewId": viewId,
      "setting": setting?.toJson()
    });
  }

  Future startStreaming() async {
    await _channel.invokeMethod("startStreaming", {
      "viewId": viewId,
    });
  }

  Future destroy() async {
    await _channel.invokeMethod("destroy", {
      "viewId": viewId,
    });
  }
}